package com.lsfb.signln.Location.TaskMsg.Leave;

import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lsfb.signln.R;
import com.lsfb.signln.Utils.URLString;
import com.zgscwjm.lsfbbasetemplate.adapter.CommonRecycAdapter;
import com.zgscwjm.lsfbbasetemplate.adapter.ViewHolderRecyc;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/10 0010.
 */

public class LeaveDetailsAdapter extends CommonRecycAdapter<LeaveDetailsBean.ListBean> {
    private Context mContext;
    private List<LeaveDetailsBean.ListBean> list = new ArrayList<>();

    public LeaveDetailsAdapter(Context context, List<LeaveDetailsBean.ListBean> list, int layoutId) {
        super(context, list, layoutId);
        mContext = context;
        this.list = list;
    }

    @Override
    public void convert(ViewHolderRecyc holder, LeaveDetailsBean.ListBean model) {
        if (model.getHeadimg() != null && !model.getHeadimg().isEmpty()) {
            holder.setVisible(R.id.item_img_head, true);
            holder.setVisible(R.id.item_text_head, false);
            holder.setImg(R.id.item_img_head, URLString.IMAGES + model.getHeadimg(), R.mipmap.img_test_head_hui);
        } else {
            holder.setVisible(R.id.item_img_head, false);
            holder.setVisible(R.id.item_text_head, true);
            holder.setText(R.id.item_text_head, model.getName().substring(model.getName().length() - 2, model.getName().length()));
        }
        holder.setText(R.id.item_tv_name, model.getName());
        holder.setText(R.id.item_tv_time, model.getTime());
        TextView tv_status = holder.getView(R.id.item_tv_status);
        ImageView iv_status = holder.getView(R.id.item_img_status);
        LinearLayout line = holder.getView(R.id.item_line);
        switch (model.getState()) {
            case 0:        //拒绝
                iv_status.setImageResource(R.mipmap.img_refuse);
                tv_status.setText("拒绝 " + model.getContent());
                tv_status.setTextColor(mContext.getResources().getColor(R.color.label_red));
                line.setBackgroundColor(mContext.getResources().getColor(R.color.line_color));
                break;
            case 1:        //同意
                iv_status.setImageResource(R.mipmap.img_pass);
                tv_status.setText("同意");
                tv_status.setTextColor(mContext.getResources().getColor(R.color.label_forgive));
                line.setBackgroundColor(mContext.getResources().getColor(R.color.label_forgive));
                break;
            default:        //待审批
                iv_status.setImageResource(R.mipmap.img_pass_hui);
                tv_status.setText("待审批");
                tv_status.setTextColor(mContext.getResources().getColor(R.color.theme_font));
                line.setBackgroundColor(mContext.getResources().getColor(R.color.line_color));
                break;
        }

        if (holder.getPosition() == list.size() - 1) {
            holder.setVisible(R.id.item_line, false);
        } else {
            holder.setVisible(R.id.item_line, true);
        }
    }
}
